package jjn.carl.dp;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/22 23:36
 */
public class LeetCode121 {
    public int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int price : prices) {
            min = Math.min(price, min);
            maxProfit = Math.max(maxProfit, price - min);
        }
        return maxProfit;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] prices = new int[count];
        for (int i = 0; i < count; i++) {
            prices[i] = scanner.nextInt();
        }
        int maxProfit = new LeetCode121().maxProfit(prices);
        System.out.println(maxProfit);
    }
}
